package island.gotenyama.wand.field;

import java.lang.reflect.Field;

import island.gotenyama.wand.annotation.FieldDefinition;
import island.gotenyama.wand.annotation.NotNull;
import island.gotenyama.wand.annotation.Length;
import island.gotenyama.wand.annotation.TimestampPattern;
import island.gotenyama.wand.bean.AField;
import island.gotenyama.wand.enums.DBFieldType;
import island.gotenyama.wand.enums.JavaFieldType;
import island.gotenyama.wand.exception.FatalException;

/**
 * 共通的に定義するフィールドを定義する。
 * 
 * @author tkawabata
 */
public enum ACmnField implements AField {

	@NotNull
	@FieldDefinition(name = "id", nameJp = "ID", typeDB = DBFieldType.INTEGER, typeJava = JavaFieldType.LONG)
	ID,

	@NotNull
	@Length(max = 100)
	@FieldDefinition(name = "create_user", nameJp = "登録者", typeDB = DBFieldType.VARCHAR, typeJava = JavaFieldType.STRING)
	CREATE_USER,

	@NotNull
	@TimestampPattern
	@FieldDefinition(name = "create_date", nameJp = "登録日", typeDB = DBFieldType.TIMESTAMP, typeJava = JavaFieldType.DATE)
	CREATE_DATE,

	@NotNull
	@Length(max = 100)
	@FieldDefinition(name = "update_user", nameJp = "更新者", typeDB = DBFieldType.VARCHAR, typeJava = JavaFieldType.STRING)
	UPDATE_USER,
	
	@NotNull
	@TimestampPattern
	@FieldDefinition(name = "update_date", nameJp = "登録日", typeDB = DBFieldType.TIMESTAMP, typeJava = JavaFieldType.DATE)
	UPDATE_DATE;
	
	@Override
	public Field getField() {
		try {
			return this.getClass().getDeclaredField(name());
		} catch (NoSuchFieldException e) {
			throw new FatalException("No Field.", e);
		}
	}

	@Override
	public FieldDefinition getFieldDefinition() {
		return getField().getAnnotation(FieldDefinition.class);
	}
}
